#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e3 + 10, INF = 0x3f3f3f3f, mod = 19650827;

int n;
int a[N], f[N][N][2];

void solve()
{
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i];
    for (int i = 1;i <= n;i++) f[i][i][0] = 1, f[i][i][1] = 0;

    for (int len = 2;len <= n;len++)
        for (int i = 1;i + len - 1 <= n;i++) {
            int j = i + len - 1;
            if (a[i] < a[i + 1]) f[i][j][0] += f[i + 1][j][0];
            if (a[i] < a[j])     f[i][j][0] += f[i + 1][j][1];
            if (a[j] > a[i])     f[i][j][1] += f[i][j - 1][0];
            if (a[j] > a[j - 1]) f[i][j][1] += f[i][j - 1][1];
            f[i][j][0] %= mod;f[i][j][1] %= mod;
        }
    cout << (f[1][n][0] + f[1][n][1]) % mod << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}